package gov.nih.nlm.lowlinc.core;

import gov.nih.nlm.lowlinc.bean.LOINCTerm;
import gov.nih.nlm.lowlinc.owlapi.LowlincException;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TermField {
	private Method method = null;
	private Integer foundCounter = 0;
	private Integer missingCounter = 0;
	private Integer matchedCounter = 0;
	private String fieldValue = null;

	public Integer getFoundCounter() {
		return foundCounter;
	}

	public void incrementFound() {
		foundCounter++;
	}

	public void resetFound() {
		foundCounter = 0;
	}

	public Boolean isFound() {
		if (foundCounter != 0) {
			return true;
		} else {
			return false;
		}
	}

	public Integer getMissingCounter() {
		return missingCounter;
	}

	public void incrementMissing() {
		missingCounter++;
	}

	public void incrementMatched() {
		matchedCounter++;
	}

	public Integer getMatchedCounter() {
		return matchedCounter;
	}

	public TermField(String methodName) throws LowlincException {
		try {
			method = LOINCTerm.class.getMethod(methodName, new Class[0]);
		} catch (NoSuchMethodException | SecurityException e) {
			throw new LowlincException(e);
		}

	}

	public TermField() {
	}

	public void setValue(LOINCTerm term) throws LowlincException {
		if (method != null) {
			try {
				fieldValue = (String) method.invoke(term, new Class[0]);
			} catch (IllegalAccessException | IllegalArgumentException
					| InvocationTargetException e) {
				throw new LowlincException(e);
			}
		}
	}

	public String getValue() {
		return fieldValue;
	}
}
